package com.zzy.email;

import java.io.File;
import java.io.IOException;

import org.junit.Test;

import jodd.mail.Email;
import jodd.mail.EmailAttachment;
import jodd.mail.SendMailSession;
import jodd.mail.SmtpServer;
import jodd.mail.SmtpSslServer;
import jodd.mail.att.FileAttachment;

/**
 * Created by simon on 2016/4/20.
 */
public class JoddMailDemo {

	// 支持html页面展示
	public static void main(String args[]) {
		String[] emails = { "243860327@qq.com" };
		SmtpServer<?> smtp = SmtpSslServer.create("smtp.exmail.qq.com");// 设置SSL的smtp服务器，我的，smtp.mxhichina.com
		smtp.authenticateWith("guokaige@topnet.net.cn", "Bss5224271");// 我的,service@www.dtxzw.com,密码省略....
		SendMailSession session = smtp.createSession();
		Email email = Email.create().from("guokaige@topnet.net.cn").subject("邮件标题")// 设置了主题
				.to(emails).addHtml("<p style='background:green'>html的文件内容！</p>");
		session.open();// 打开连接
		session.sendMail(email);// 发送邮件
		session.close();// 关闭连接
		System.out.println("发送成功");
	}
	// 支付多附件
	// public static void main(String ss[]) throws IOException {
	// sendMail("zhangxiangfeng@sudaotech.com","/home/simon/桌面/cwch824.2/cwch/WebRoot/download/yingyu/英语选修6电子档.pdf");
	// }

	@Test
	public void sendMail() throws IOException {
		 String mail="243860327@qq.com";
		 String filePath="E:\\java\\123.png";
		
		EmailAttachment attachment = new FileAttachment(new File(filePath), "123.png", "png");
		String[] emails = { mail };
		SmtpServer<?> smtp = SmtpSslServer.create("smtp.exmail.qq.com", 465);
		smtp.authenticateWith("guokaige@topnet.net.cn", "Bss5224271");
		SendMailSession session = smtp.createSession();
		Email email = Email.create().from("guokaige@topnet.net.cn").subject("考的好系统邮件").to(emails).attach(attachment).attach(attachment).addText("你好,你下载的内容在附件里面");
		session.open();// 打开连接
		session.sendMail(email);// 发送邮件
		session.close();// 关闭连接
		System.out.println("发送邮件成功");
	}



}